package com.xinruke.hostels.central.manage.controller;

import com.xinruke.hostels.central.manage.interfaces.dto.*;
import com.xinruke.hostels.central.manage.service.NoticeService;
import com.xinruke.hostels.common.controller.BaseController;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @ClassName NoticeController
 * @CreateDate 2019/6/12
 * @Author FengXinQiang
 * @Version V1.0.0.0
 * @Decription 公告
 */
@RestController
@RequestMapping("notice/")
@Api(tags = "公告")
public class NoticeController extends BaseController {

    @Resource
    private NoticeService noticeService;

    @PostMapping(value = "list")
    @ApiOperation(value = "查询公告列表")
    public ResultVO<RowsDataVO<NoticeQueryResultDTO>> getNoticeList(@RequestBody NoticeQueryDTO noticeQueryDTO) {
        ResultVO<RowsDataVO<NoticeQueryResultDTO>> resultVO = ResultVO.fail();
        RowsDataVO<NoticeQueryResultDTO> dataVO = noticeService.getNoticeList(noticeQueryDTO);
        resultVO.setCode(ResultVO.SUCCESS);
        resultVO.setMessage("操作成功");
        resultVO.setData(dataVO);
        return resultVO;
    }

    @PostMapping(value = "detail")
    @ApiOperation(value = "查询公告详情")
    public ResultVO<NoticeDetailQueryResultDTO> getNoticeDetail(@RequestBody NoticeDetailQueryDTO noticeDetailQueryDTO) {
        ResultVO<NoticeDetailQueryResultDTO> resultVO = ResultVO.fail();
        NoticeDetailQueryResultDTO dataVO = noticeService.getNoticeDetail(noticeDetailQueryDTO);
        resultVO.setCode(ResultVO.SUCCESS);
        resultVO.setMessage("操作成功");
        resultVO.setData(dataVO);
        return resultVO;
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "添加公告")
    public ResultVO addNotice(@Valid @RequestBody NoticeAddDTO noticeAddDTO) {
        ResultVO resultVO = ResultVO.fail();
        int n = noticeService.addNotice(noticeAddDTO);
        if (n > 0) {
            resultVO.setCode(ResultVO.SUCCESS);
            resultVO.setMessage("操作成功");
        }
        return resultVO;
    }

    @PostMapping(value = "modify")
    @ApiOperation(value = "修改公告")
    public ResultVO modifyNotice(@Valid @RequestBody NoticeModifyDTO noticeModifyDTO) {
        return noticeService.modify(noticeModifyDTO);
    }

    @PostMapping(value = "release")
    @ApiOperation(value = "发布公告")
    public ResultVO release(@Valid @RequestBody NoticeReleseOrRevokeDTO noticeReleseDTO) {
        return noticeService.release(noticeReleseDTO);
    }

    @PostMapping(value = "revoke")
    @ApiOperation(value = "撤销公告")
    public ResultVO revoke(@Valid @RequestBody NoticeReleseOrRevokeDTO noticeReleseDTO) {

        return noticeService.revoke(noticeReleseDTO);
    }

    @PostMapping(value = "del")
    @ApiOperation(value = "废除公告")
    public ResultVO del(@Valid @RequestBody NoticeReleseOrRevokeDTO noticeReleseDTO) {
        return noticeService.del(noticeReleseDTO);
    }
}
